import { http } from '@/utils/http'

export interface ICartResult {
  cartonSpec: string
  mainPic: string
  price: number
  productName: string
  productSpec: string
  quantity: number
  storeCode: string
  upcCode: string
}

export const getCart = (storeCode: string) => {
  return http.get<ICartResult[]>('/jeecg-boot/htmmp/shopcart/getCart?storeCode=' + storeCode)
}

export const clearCart = (storeCode: string) => {
  return http.get('/jeecg-boot/htmmp/shopcart/clearCart?storeCode=' + storeCode)
}

export interface ICartParams {
  price: number
  quantity: number
  storeCode: string
  upcCode: string
}

export const addShopcart = (data: ICartParams) => {
  return http.post('/jeecg-boot/htmmp/shopcart/addShopcart', data)
}

export const removeShopcartItem = (data: ICartParams) => {
  return http.post('/jeecg-boot/htmmp/shopcart/removeShopcartItem', data)
}

export interface IOrderParams {
  storeCode: string
  orderNote: string
}

export interface IOrderResult {
  totalAmount: string
  orderCode: string
  receiveInfo: string
}

export const submitOrder = (query: IOrderParams) => {
  return http.get<IOrderResult>('/jeecg-boot/htmmp/shopcart/submitOrder', query)
}

export interface IPreUnifieAppletdorderResult {
  useAppid: string
  appletUrl: string
}

export const preUnifieAppletdorder = (orderCode: string) => {
  return http.get<IPreUnifieAppletdorderResult>(
    `/jeecg-boot/htmmp/shopcart/preUnifieAppletdorder?orderCode=${orderCode}`,
  )
}
